package cn.class2.function

/**
  * Created by lzd on 2018/11/5.
  * 函数的定义
  * 函数的说明
  */
object function1 {
  def main(args: Array[String]): Unit = {

    val f1 = (x: Int, y: Int) => {x + y}
    println(f1)

    val f2: (Int, Int) => Int = { (x, y) => {x + y}}
    println(f2)

    /** 第一个和二个Int是参数类型，第三个Int是返回值类型 */
    val f3 = new Function2[Int, Int, Int] {
      override def apply(v1: Int, v2: Int) = {
        v1 + v2
      }
    }

    val arr = Array(1, 2, 3, 4, 5, 6, 7, 8)
    val map = arr.map((x) => {x * x})
    println(map.toBuffer)
    println(arr.map((_ * 10)).toBuffer)
    val arrmap :Array[Int] = arr.map(_ * 10)
    println(arrmap.toBuffer)

    val arr2 = arr.filter(_ % 2 != 0)
    println(arr2.toBuffer)
  }
}
